{  Statement: http://acmp.ru/?main=task&id_task=29
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i, n : longint;
    a, f : array[0..30010] of longint;

begin
    reset(input,'input.txt');
    rewrite(output,'output.txt');
    read(n);
    for i := 1 to n do 
        read(a[i]);
    f[1] := 0;
    f[0] := round(1e9);
    for i := 2 to n do
        f[i] := min(f[i - 1] + abs(a[i] - a[i - 1]), f[i - 2] + 3 * abs(a[i] - a[i - 2]));
    write(f[n]);
end.